package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.ExpressInfo;
import com.zjhd.sealcutting.domain.PressOrganization;
import com.zjhd.sealcutting.param.ExpressSearchQuery;
import com.zjhd.sealcutting.param.PressOrganizationSearchQuery;
import com.zjhd.sealcutting.service.PressOrganizationService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.SearchResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO  印机构管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/27 15:40
 */
@Api(value = "印机构管理", tags = "印机构管理")
@RequestMapping("/pressOrganization")
@RestController
public class PressOrganizationController {

    private final static Logger logger = LoggerFactory.getLogger(PressOrganizationController.class);

    @Autowired
    private PressOrganizationService pressOrganizationService;

    @ApiOperation(value = "分页查询印机构列表接口", notes = "分页查询印机构列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型  (1:印吧、2:印社、3:企业、4:院校、5:学校、6:事业单位  )", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态(  0:启用  1：禁用)", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryPressOrganizationParamlist")
    public ResponseResult<SearchResult<PressOrganization>> queryPressOrganizationParamlist(PressOrganizationSearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.queryPressOrganizationParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询印机构列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询印机构列表接口失败");
        }
    }

    @ApiOperation(value = "新增印机构", notes = "新增印机构接口")
    @PostMapping("/insertPressOrganization")
    @OperLog(operModul = "印机构管理-新增印机构",operType = "新增",operDesc = "新增印机构")
    public ResponseResult insertPressOrganization(@RequestBody PressOrganization pressOrganization){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.insertPressOrganization(pressOrganization));
        }catch (Exception ex) {
            logger.error("新增印机构接口失败", ex);
            return ResultGenerator.genFailResult("新增印机构接口失败");
        }
    }

    @ApiOperation(value = "修改印机构", notes = "修改印机构接口")
    @PostMapping("/updatePressOrganization")
    @OperLog(operModul = "印机构管理-修改印机构",operType = "修改",operDesc = "修改印机构")
    public ResponseResult updatePressOrganization(@RequestBody PressOrganization pressOrganization){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.updatePressOrganization(pressOrganization));
        }catch (Exception ex) {
            logger.error("修改印机构接口失败", ex);
            return ResultGenerator.genFailResult("修改印机构接口失败");
        }
    }

    @ApiOperation(value = "删除印机构", notes = "删除印机构接口")
    @PostMapping("/delPressOrganization")
    @OperLog(operModul = "印机构管理-删除印机构",operType = "删除",operDesc = "删除印机构")
    public ResponseResult delPressOrganization(@RequestParam(value = "id",defaultValue = "")Integer id){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.delPressOrganization(id));
        }catch (Exception ex) {
            logger.error("删除印机构接口失败", ex);
            return ResultGenerator.genFailResult("删除印机构接口失败");
        }
    }

    @ApiOperation(value = "查询印机构信息详情", notes = "查询印机构信息详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "印机构ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByIdPressOrganization")
    @OperLog(operModul = "印机构管理-查看印机构",operType = "查询",operDesc = "查看印机构")
    public ResponseResult queryByIdPressOrganization(Integer id){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.queryByIdPressOrganization(id));
        }catch (Exception ex) {
            logger.error("查询印机构信息详情接口失败", ex);
            return ResultGenerator.genFailResult("查询印机构信息详情接口失败");
        }
    }

    @ApiOperation(value = "禁用或启用印机构", notes = "禁用或启用印机构接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "印机构ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "启用类型  0:启用 1:禁用", dataType = "Integer", paramType = "query")
    })
    @PostMapping("/disableOrEnablePress")
    @OperLog(operModul = "印机构管理-禁用或启用印机构",operType = "修改",operDesc = "禁用或启用印机构")
    public ResponseResult disableOrEnablePress(@RequestParam(value = "id",defaultValue = "")Integer id,@RequestParam(value = "state",defaultValue = "")Integer state){
        try{
            return ResultGenerator.genSuccessResult(pressOrganizationService.disableOrEnablePress(id,state));
        }catch (Exception ex) {
            logger.error("禁用或启用印机构接口失败", ex);
            return ResultGenerator.genFailResult("禁用或启用印机构接口失败");
        }
    }
}
